/**
 * @Author Puzzle
 * @Date 2022/6/20 9:57 上午
 **/

package api

import (
	"github.com/gin-gonic/gin"
	"github.com/mojocn/base64Captcha"
	"zsc-boot/core"
	"zsc-boot/core/web"
)

// Captcha 获取图形验证码
func Captcha(ctx *gin.Context) {
	driver := base64Captcha.NewDriverDigit(80, 240, 6, 0.7, 80)
	cp := base64Captcha.NewCaptcha(driver, core.Cache())
	if id, b64s, _, err := cp.Generate(); err != nil {
		web.FailResponse(ctx, err, "二维码生成失败")
	} else {
		web.SuccessResponse(ctx, gin.H{
			"captchaId":     id,
			"picPath":       b64s,
			"captchaLength": 6,
		})
	}
}
